package top.tervest.easyshare.common.security.handler;

import lombok.extern.log4j.Log4j2;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;
import top.tervest.easyshare.common.Result;
import top.tervest.easyshare.common.constant.ResponseState;
import top.tervest.easyshare.common.exception.PasswordErrorException;
import top.tervest.easyshare.common.exception.UserNotFoundException;
import top.tervest.easyshare.common.util.HttpUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author ZhangNanNan
 * @create 2019-07-18 10:05
 */
@Component
@Log4j2
public class CustomAuthenticationEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        Result failure = Result.failure(ResponseState.LOGIN_FAILURE, authException.getMessage());
        log.error(authException.getMessage());
        HttpUtil.writeJson(response,failure);
    }
}
